package top.malaoshi.netdisk.service;

import org.springframework.stereotype.Service;
import top.malaoshi.netdisk.exception.LoginException;
import top.malaoshi.netdisk.vo.JsonCodeMsg;
import top.malaoshi.netdisk.vo.User;
import top.malaoshi.sprout.jdbc.DbTemplate;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;

@Service
public class LoginSrvImpl {

    @Resource
    private DbTemplate jdbcTemplate;
    public User login(User user) throws SQLException {
        String sql = "select uid,username from t_user where username = #{username} and password = #{password}";
        List<User> list = jdbcTemplate.queryTag(User.class,sql,user);

        if(list == null || list.size() == 0){
            throw new LoginException(JsonCodeMsg.LOGIN_FAIL.getCode(), JsonCodeMsg.LOGIN_FAIL.getMsg());
        }

        return list.get(0);
    }
}
